package com.xinghai.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xinghai.common.exception.ServiceException;
import java.io.IOException;

import com.xinghai.common.utils.DateUtils;
import com.xinghai.common.utils.PageUtils;
import com.xinghai.domain.JkqActivity;
import com.xinghai.service.IJkqActivityService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xinghai.common.annotation.Log;
import com.xinghai.common.core.controller.BaseController;
import com.xinghai.common.core.domain.AjaxResult;
import com.xinghai.common.enums.BusinessType;
import com.xinghai.domain.JkqActivityAddress;
import com.xinghai.service.IJkqActivityAddressService;
import com.xinghai.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;
import com.xinghai.common.core.page.TableDataInfo;

/**
 * 活动地址管理Controller
 *
 * @author xinghai
 * @date 2025-08-02
 */
@RestController
@RequestMapping("/system/activityAddress")
public class JkqActivityAddressController extends BaseController
{
    @Autowired
    private IJkqActivityAddressService jkqActivityAddressService;

    @Autowired
    private IJkqActivityService jkqActivityService;

    /**
     * 查询活动地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:list')")
    @GetMapping("/list")
    public AjaxResult list(JkqActivityAddress jkqActivityAddress)
    {
        List<JkqActivityAddress> list = jkqActivityAddressService.list(jkqActivityAddress);
        return success(list);
    }


    /**
     * 查询活动地址管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:activityAddress:list')")
    @GetMapping("/activityList")
    public AjaxResult activityList(JkqActivity jkqActivity)
    {
        PageUtils.orderBy("create_time desc");
        //jkqActivity.setStatus("0");
        List<JkqActivity> list = jkqActivityService.list(jkqActivity);
        return success(list);
    }

    /**
     * 查询活动地址管理列表(带分页)
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:list')")
    @GetMapping("/page")
    public TableDataInfo page(JkqActivityAddress jkqActivityAddress)
    {
        startPage();
        List<JkqActivityAddress> list = jkqActivityAddressService.list(jkqActivityAddress);
        return getDataTable(list);
    }

    /**
     * 导出活动地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:export')")
    @Log(title = "活动地址管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JkqActivityAddress jkqActivityAddress)
    {
        List<JkqActivityAddress> list = jkqActivityAddressService.list(jkqActivityAddress);
        ExcelUtil<JkqActivityAddress> util = new ExcelUtil<JkqActivityAddress>(JkqActivityAddress.class);
        util.exportExcel(response, list, "活动地址管理数据");
    }

    /**
     * 获取活动地址管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:query')")
    @GetMapping("/getInfo")
    public AjaxResult getInfo(Long id)
    {
        return success(jkqActivityAddressService.getById(id));
    }

    /**
     * 新增活动地址管理
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:add')")
    @Log(title = "活动地址管理", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody JkqActivityAddress jkqActivityAddress)
    {
        jkqActivityAddress.setCreateTime(DateUtils.getNowDate());
        jkqActivityAddress.setCreateBy(getUsername());
        return toAjax(jkqActivityAddressService.save(jkqActivityAddress));
    }

    /**
     * 修改活动地址管理
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:edit')")
    @Log(title = "活动地址管理", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody JkqActivityAddress jkqActivityAddress)
    {
        jkqActivityAddress.setUpdateTime(DateUtils.getNowDate());
        jkqActivityAddress.setUpdateBy(getUsername());
        return toAjax(jkqActivityAddressService.updateById(jkqActivityAddress));
    }

    /**
     * 删除活动地址管理
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:remove')")
    @Log(title = "活动地址管理", businessType = BusinessType.DELETE)
	@PostMapping("/delete")
    public AjaxResult delete(Long id)
    {
        return toAjax(jkqActivityAddressService.removeById(id));
    }


    /**
     * 批量删除活动地址管理
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:remove')")
    @Log(title = "活动地址管理", businessType = BusinessType.DELETE)
    @PostMapping("/deleteBatch")
    public AjaxResult deleteBatch(Long[] ids)
    {
        return toAjax(jkqActivityAddressService.removeBatchByIds(Arrays.asList(ids)));
    }

    /**
     * 导入活动地址管理模板
     */
    @PreAuthorize("@ss.hasPermi('system:activityAddress:import')")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JkqActivityAddress> util = new ExcelUtil<JkqActivityAddress>(JkqActivityAddress.class);
        util.importTemplateExcel(response, "活动地址管理数据模板");
    }


    /**
     * 导入活动地址管理
     */
    @Log(title = "活动地址管理管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:activityAddress:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file)
    {
        ExcelUtil<JkqActivityAddress> util = new ExcelUtil<JkqActivityAddress>(JkqActivityAddress.class);
        List<JkqActivityAddress> jkqActivityAddressList = null;
        try {
            jkqActivityAddressList = util.importExcel(file.getInputStream());
        } catch (IOException e) {
            throw new ServiceException("导入数据失败");
        }
        return success(jkqActivityAddressService.importData(jkqActivityAddressList));
    }
}
